<%@page import="com.easyattendance.services.AddClassService"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
<%@page import="com.easyattendance.model.StudentLeave"%>	
<%@page import="java.text.DateFormat" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@page import="com.easyattendance.model.Student"%>
<%@page import="com.easyattendance.model.AssignmentStudent"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.easyattendance.model.Student"%>
<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@page import="com.easyattendance.services.AddStudentService"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Teacher - View Student List</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" />

<!-- fooTable Links -->
<link href="../css/footable.core.css" rel="stylesheet" type="text/css" />
<link href="../css/footable.metro.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/public/js/footable.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/public/js/footable.sort.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function () {
		$('.footable').footable();
	});
</script>

<!-- ***************************************** -->
</head>

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp" />
<jsp:include page="../common/checkTeacherRole.jsp" />

<% String currentUser = (String) session.getAttribute("currentUser"); 
	AddTeacherService addTeacherService = new AddTeacherService();
	Teacher teacher = addTeacherService.getTeacherByEmailId(currentUser);
	String teacher_id=teacher.getTeacher_id().toString();
	String sectionEmail=addTeacherService.getSectionEmailIdByTeacherId(currentUser);
	System.out.println("current_user="+currentUser);
	System.out.println("teacher_id="+teacher.getTeacher_id().toString()); 

 %>

<%
	ArrayList<Student> studList=(ArrayList<Student>)session.getAttribute("student_list");
	ArrayList<StudentLeave> leaveList=(ArrayList<StudentLeave>)session.getAttribute("leave_list");

	DateFormat dateFormat=new SimpleDateFormat("dd-MM-YYYY");
	Date date=new Date();

	String sys_dt=dateFormat.format(date);
	String classid=(String)session.getAttribute("classid"); 
	//String classid = addClassService.getClassIdByTeacherId(currentUser);
	
	
%>
	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">
			
				<span class="error_msg">${attendanceExists}</span>
				<span class="sucess_msg">${attendanceSaved}</span>
				<span class="error_msg">${attendanceNotSaved}</span>
				
				<!-- Login -->
				
	 <form name="viewAttendanceStudentList" action="${pageContext.request.contextPath}/AttendanceSubmissionServlet" method="post" class="gridview">  
		Attendance Date: <input type="text" name="attendance_dt" value="<%=sys_dt %>" id="attendance_dt" readonly="readonly"/>
		
		<table name="attendance" id="tbl_attendance" class="footable metro-attendance">
                <thead>
                <tr>
                    <th data-toggle="true" data-sort-initial="true">
                        Roll No.
                    </th>
                    <th data-toggle="true">
                        Student Name
                    </th>
                    <th data-hide="phone,tablet" data-sort-ignore="true">
                        Last Name
                    </th>  
                    <th data-toggle="true" data-sort-ignore="true">
                        Present
                    </th>
                    <th data-toggle="true" data-sort-ignore="true">
                        Absent
                    </th>
                    <th data-toggle="true" data-sort-ignore="true">
                        Leave Granted
                    </th>
                </tr>
                </thead>
              <tbody>
		<% for(int i = 0; i < studList.size(); i++) { %>
		<tr>
		
			<td data-value="<%=studList.get(i).getStud_roll_no()%>">
					<input type="text" name="stud_roll_no" value="<%=studList.get(i).getStud_roll_no() %>" id="stud_id" readonly="readonly"/>
			</td>
			
			 <td data-value="<%=studList.get(i).getStud_fname().toString() %>">
				<input type="text" name="stud_name" value="<%=studList.get(i).getStud_fname().toUpperCase().toString()%>" id="stud_name" readonly="readonly"/>
			</td>
			
			<td>
				 <input type="text" id="stud_lname" name="stud_lname" value="<%=studList.get(i).getStud_lname().toUpperCase().toString() %>" readonly="readonly"/>
			</td> 
			
		  <%
		  		int studid=studList.get(i).getStud_roll_no();
		  		int flag=0;
				for(int j=0;j<leaveList.size();j++)
				{
					 int id=leaveList.get(j).getStud_roll_no();
					 
					 if(studid==id)
					 {
							flag=1;
							//break;
					 }
				}
				
		 	 %>	    

			<td><input type="radio" name="status<%=i%>" id="present" value="present"/> </td>
			<td><input type="radio" name="status<%=i%>" id="absent" value="absent"/></td>
			 
			  <%if(flag==1){ %>
					<TD><input type="radio" name="status<%=i%>" id="leave" value="leave" checked></TD>
					
			<% }else if(flag==0){%>
					
		    		<TD><input type="radio" name="status<%=i%>" id="leave" value="leave"/></TD>
			<% } %>   
			 
		</TR>
	
		<% } %>
	
	 </tbody>
   </table>
	
				<!-- Hidden fields -->
				<div>
				    <input type="hidden" name="teacher_id" id="teacher_id" value="<%=teacher_id%>">  
					<input type="hidden" name="class_id" id="class_id" value="<%=classid%>"> 
					<input type="hidden" name="section_email" id="section_email" value="<%=sectionEmail%>"> 
				</div>
				
				<div>	
					<input type="submit" value="Submit Attendance" class="button add_button">
					<input type="submit" value="Edit" class="button add_button" disabled="disabled" action="editAttendance.jsp">
				</div>
	
		</form>
	</div>
  </div>
  
		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" />

			<jsp:include page="teacherMenu.jsp" />

			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>	
	<script type="text/javascript">
		$(function(){
			$("#takeAttendance").addClass("current_page_item");
		});
	</script>
</body>
</html>